n,k=map(int,input().split())
if k==0:
print(1)
else:
print(min(k,n-k))
#include "bits/stdc++.h"
using namespace std;
#define mod 1000000007
#define MOD1 998244353
#define rep(i,b) for(int i = 0; i < b; i++)
#define nl "\n"
#define sp " "
#define inf 1e9 + 4
#define pb push_back
#define vi vector<int>
#define all(x) (x).begin(), (x).end()
#define ys cout << "YES" << nl
#define no cout << "NO" << nl
#define pi 3.141592653589793238462
#define ll long long
// #define int long long
template<typename T> istream& operator>>(istream& is, vector<T> &v){for (auto& i : v) is >> i; return is;}
template<typename T> ostream& operator<<(ostream& os, vector<T> v){for (auto& i : v) os << i << ' '; return os;}
vector<ll> sieve(int n) {int*v = new int[n + 1](); vector<ll> vect; for (int i = 2; i <= n; i++)if (v[i] == 0) {vect.push_back(i); for (int j = 2 * i; j <= n; j += i)v[j] = 1;} return vect;}
void solve(){
int n , m; cin >> n >> m;
if(m == 0) cout << 1 << nl;
else if(m == n){
cout << 0 << nl;
}
else cout << (min(n - m , m)) << nl;
}
signed main(){
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int t = 1;
// cin >> t;
while(t--){
solve();
}
return 0;
}
1047B - Cover Points | 1381B - Unmerge |
1256A - Payment Without Change | 908B - New Year and Buggy Bot |
979A - Pizza Pizza Pizza | 731A - Night at the Museum |
742A - Arpa’s hard exam and Mehrdad’s naive cheat | 1492A - Three swimmers |
1360E - Polygon | 1517D - Explorer Space |
1230B - Ania and Minimizing | 1201A - Important Exam |
676A - Nicholas and Permutation | 431A - Black Square |
474B - Worms | 987B - High School Become Human |
1223A - CME | 1658B - Marin and Anti-coprime Permutation |
14B - Young Photographer | 143A - Help Vasilisa the Wise 2 |
320A - Magic Numbers | 1658A - Marin and Photoshoot |
514A - Chewbaсca and Number | 382A - Ksenia and Pan Scales |
734B - Anton and Digits | 1080A - Petya and Origami |
1642D - Repetitions Decoding | 1440A - Buy the String |
1658F - Juju and Binary String | 478A - Initial Bet |